package com.example.server.exception;

import com.example.server.model.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class RestExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result<Object> exception(Exception e){
        return Result.error(e.getMessage());
    }

    @ExceptionHandler(CustomException.class)
    public Result<Object> customException(CustomException e){
        return Result.error(e.getErrorCode(), e.getMessage());
    }
}
